<%@ page contentType="text/html; charset=UTF-8" language="java"
	import="java.util.*,org.yoao.crm.acl.ACLTool,org.yoao.crm.bean.Session,org.yoao.crm.bean.StaticBean,org.yoao.crm.bean.CustomerType,org.yoao.crm.page.framework.IViewPageService,org.yoao.crm.page.framework.ViewPageHelper,org.yoao.crm.bean.Customer"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";

	Session userSession = (Session) session.getAttribute("userSession");
	String actionPermission = userSession.getActionPermission();

	IViewPageService customerPage = (IViewPageService) session
			.getAttribute(ViewPageHelper.SESSION_PAGE);

	List list = (List) request.getAttribute("CUSTOMERLIST");
	List typeList = (List) request.getAttribute("CUSTOMERTYPE");
	String roleId = (String) request.getAttribute("ROLEID");

	String searchCustomerId = (String) request
			.getAttribute("searchCustomerId");
	if (searchCustomerId == null)
		searchCustomerId = "";
	String searchCustomerName = (String) request
			.getAttribute("searchCustomerName");
	if (searchCustomerName == null)
		searchCustomerName = "";
	String searchCompanyName = (String) request
			.getAttribute("searchCompanyName");
	if (searchCompanyName == null)
		searchCompanyName = "";
	String searchProvince = (String) request
			.getAttribute("searchProvince");
	if (searchProvince == null)
		searchProvince = "";
	String searchCity = (String) request.getAttribute("searchCity");
	if (searchCity == null)
		searchCity = "";
	String searchState = (String) request.getAttribute("searchState");
	if (searchState == null)
		searchState = "";
	String searchMobile = (String) request.getAttribute("searchMobile");
	if (searchMobile == null)
		searchMobile = "";
	String searchSignature = (String) request
			.getAttribute("searchSignature");
	if (searchSignature == null)
		searchSignature = "";
	String searchUserName = (String) request
			.getAttribute("searchUserName");
	if (searchUserName == null)
		searchUserName = "";
	String searchUserSno = (String) request
			.getAttribute("searchUserSno");
	if (searchUserSno == null)
		searchUserSno = "";
	String searchAmount = (String) request.getAttribute("searchAmount");
	if (searchAmount == null)
		searchAmount = "";
	String searchType = (String) request.getAttribute("searchType");
	if (searchType == null)
		searchType = "";
%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>CRM-客户列表</title>
		<jsp:include page="../public/publicJs.jsp" flush="false"></jsp:include>
		<SCRIPT Language="Javascript" SRC="<%=basePath%>js/json/json2.js"></SCRIPT>
		<SCRIPT Language="Javascript" SRC="<%=basePath%>js/json/json.js"></SCRIPT>
		<SCRIPT Language="Javascript" SRC="<%=basePath%>js/customer.js"></SCRIPT>
		<script type="text/javascript">
var preTr = null;
var preColor = "";
function changeTrColor() {
	try {
		var tag = event.srcElement;
		while (tag.tagName != "TR")
			tag = tag.parentElement;
		switch (event.type) {
		case "mouseover":
			preColor = tag.currentStyle.backgroundColor;
			if (tag.currentStyle.highLightColor)
				tag.style.background = tag.currentStyle.highLightColor;
			else
				tag.style.background = "#FFFF00";
			break;
		case "mouseout":
			if (preTr != tag)
				tag.style.background = preColor;
			break;
		}
	} catch (E) {
	}
}

function openUser(id) {
	var user = window.showModalDialog(
			"<%=basePath%>kmjsp/dialog/datawindowUser.jsp", "用户选择",
			"dialogWidth=300px;dialogHeight=380px");
	if ("CANCELUSER" == user)
		return;
	if (user == "")
		user = "|";
	if (!user)
		return;

	var sarray = user.split("|");
	if (sarray != null) {
		if (id) {
			if (!id || id == "") {
				alert("未获取到报名人ID,数据未同步到客户中心!");
				return;
			}
			var vUrl = "<%=basePath%>customer.crm?method=distribution&id=" + id
					+ "&sno=" + sarray[0];
			var result = ajax_getReturnText(vUrl);
			if (result.indexOf("[SUCCESS]") > -1) {
				location.reload();
			} else
				alert(result);
		} else {
			var objSno = document.all.searchUserSno;
			for ( var i = 0; i < objSno.length; i++) {
				objSno[i].value = sarray[0];
			}

			var objName = document.all.searchUserName;
			for ( var i = 0; i < objName.length; i++) {
				objName[i].value = sarray[1];
			}
		}
	}
}
function showCustomerAttributes(customerId, customerName) {
	var src = event.srcElement;
	src.src = src.src.indexOf("_b") != -1 ? src.src.replace(/_b/g, "_a")
			: src.src.replace(/_a/g, "_b");
	try {
		fn_changeDivHeight()
	} catch (E) {
	}
	reinitIframe(0);
	var vTag = document.getElementById("tr_attribute_" + customerId);
	vTag.style.display = (vTag.style.display && vTag.style.display != "") ? ""
			: "none";
	if (vTag.style.display == "") {
		var divLoad = document.getElementById("ds_attr_load_" + customerId);
		divLoad.style.pixelLeft = event.clientX;
		divLoad.style.pixelTop = event.clientY - 90;
		divLoad.style.display = "block";
		var searchState = document.getElementById("searchState").value;
		var searchSignature = document.getElementById("searchSignature").value;
		var searchAmount = document.getElementById("searchAmount").value;
		var url = "<%=basePath%>customerAttributes.crm?method=view&cid="
				+ customerId + "&searchAmount=" + searchAmount
				+ "&searchState=" + searchState + "&searchSignature="
				+ searchSignature;
		var result = ajax_getReturnText(url).parseJSON();
		if (result != "") {
			var tableName = "table_" + customerId;
			deleteRow(tableName);

			for ( var i = 0; i < result.length; i++) {
				var value = new Array();
				value[0] = result[i].id;
				value[1] = result[i].state;
				value[2] = result[i].signature;
				value[3] = result[i].signTime;
				value[4] = result[i].amount;
				value[5] = result[i].payTime;
				value[6] = result[i].customerId;
				if (value[2] == 1)
					value[2] = "已签到";
				else
					value[2] = "未签到";
				addRow(tableName, value, customerName, customerId);
			}
		}
		divLoad.style.display = "none";
		document.getElementById("div_content_" + customerId).style.display = "block";
	}
}
</script>
	</head>

	<body topmargin="0" leftmargin="0"
		onLoad="setDivHeight('divList', -160);">
		<div id="div_load"
			style='display: block; background: #FFFFFF; width: 240px; height: 12px; margin-top: -90px; margin-left: -200px; left: 50%; top: 50%; position: absolute; padding: 5px 5px 5px 5px; z-index: 1'>
			<img src="<%=basePath%>images/loading.gif" class="icon1"
				align="absmiddle" />
			数据加载中,请稍后...
		</div>
		<table class="maintab_content_table" border="0" width="100%"
			cellspacing="0" cellpadding="0" height="25">
			<tr class="tree_title_txt">
				<td nowrap width="100%" class="tree_title_txt" valign="middle"
					id="cwCellTopTitTxt">
					<font color="#154288">客户列表 </font>
				</td>
			</tr>
		</table>

		<div id="ds"
			style="display: none; background: #EBEBEB; width: 100px; height: 20px; left: 50%; top: 50%; position: absolute; padding: 5px 5px 5px 5px; z-index: 1">
			<font color="#FF0000"><img
					src="<%=basePath%>images/loading.gif" alt="数据加载中" align="absmiddle" />数据加载中...</font>
		</div>
		<div style="width: 100%;">
			<fieldset
				style="width: 100%; TEXT-ALIGN: center; margin: 0px 5px 0px 5px;">
				<legend>
					&nbsp;搜索
					<img name="Changeicon" border="0"
						src="<%=basePath%>images/jt_b.gif"
						onClick="javascript:fieldsetHidden();" style="cursor: hand"
						title="显示/隐藏内容">
					&nbsp;
				</legend>
				<form name="searchForm"
					action="<%=basePath%>customer.crm?method=search" method="post">
					<center>
						<table border="0" width="100%" cellspacing="5" cellpadding="0">
							<tr>
								<td nowrap>
									客户码:
								</td>
								<td>
									<input name="searchCustomerId" accesskey="s" type="text"
										class="text_220" style="width: 130px" size="25"
										value="<%=searchCustomerId%>">
								</td>
								<td nowrap>
									客户名称:
								</td>
								<td>
									<input name="searchCustomerName" accesskey="s" type="text"
										class="text_220" style="width: 130px" size="25"
										value="<%=searchCustomerName%>">
								</td>
								<td nowrap>
									公司名称:
								</td>
								<td>
									<input name="searchCompanyName" accesskey="s" type="text"
										class="text_220" style="width: 130px" size="25"
										value="<%=searchCompanyName%>">
								</td>
								<td nowrap>
									省份:
								</td>
								<td>
									<input name="searchProvince" accesskey="s" type="text"
										class="text_220" style="width: 130px" size="25"
										value="<%=searchProvince%>">
								</td>
							</tr>
							<tr>
								<td nowrap>
									是否签到:
								</td>
								<td>
									<select id="searchSignature" name="searchSignature"
										class="text_220" style="width: 130px;">
										<option value="">
											<option value="1" <%if ("1".equals(searchSignature)) {%>
												selected <%}%>>
												已签到
												<option value="0" <%if ("0".equals(searchSignature)) {%>
													selected <%}%>>
													未签到
									</select>
								</td>
								<td nowrap>
									课程类别:
								</td>
								<td>
									<select id="searchState" name="searchState"
										style="width: 130px;">
										<option value="">
											<%
												if (typeList != null && !typeList.isEmpty()) {
													for (int i = 0; i < typeList.size(); i++) {
														CustomerType customerType = (CustomerType) typeList.get(i);
											%>
											<option value="<%=customerType.getTypeCode()%>"
												<%if (customerType.getTypeCode().equals(searchState)) {%>
												selected <%}%> /><%=customerType.getTypeName()%>
												<%
													}
													}
												%>

									</select>
								</td>

								<td nowrap>
									服务人员:
								</td>
								<td>
									<input name="searchUserName" value="<%=searchUserName%>"
										type="text" style="width: 105px" class="text_220" size="15"
										readonly>
									<input name="searchUserSno" type="hidden"
										value="<%=searchUserSno%>">
									<img src="<%=basePath%>images/sbtn_more.gif" alt="用户选择"
										onclick="openUser();" width="19" height="19" align="absmiddle"
										style="cursor: pointer" />
								</td>

								<td nowrap>
									城市:
								</td>
								<td>
									<input name="searchCity" accesskey="s" type="text"
										class="text_220" style="width: 130px" size="25"
										value="<%=searchCity%>">
								</td>
							</tr>
							<tr>
								<td>
									联系手机:
								</td>
								<td>
									<input name="searchMobile" style="width: 130px"
										class="text_220" type="text" size="25"
										value="<%=searchMobile%>">
								</td>
								<td>
									客户类型:
								</td>
								<td>
									<select id="searchType" name="searchType" style="width: 130px;">
										<option value="">
											<option value="A" <%if ("A".equals(searchType)) {%> selected
												<%}%> />
												A类
												<option value="B" <%if ("B".equals(searchType)) {%> selected
													<%}%> />
													B类
													<option value="C" <%if ("C".equals(searchType)) {%>
														selected <%}%> />
														C类
														<option value="D" <%if ("D".equals(searchType)) {%>
															selected <%}%> />
															D类
									</select>
								</td>
								<td>
									已付金额:
								</td>
								<td>
									<input name="searchAmount" id="searchAmount"
										style="width: 130px" class="text_220" type="text" size="25"
										value="<%=searchAmount%>">
								</td>

								<td>
									<input name="image" type="image"
										src="<%=basePath%>images/tbtn_searh.gif" alt="查询"
										align="absmiddle" onclick="searchForm.submit();">
								</td>
							</tr>
						</table>
					</center>
				</form>
			</fieldset>
		</div>

		<form action="<%=basePath%>customer.crm?method=search" name="viewForm"
			method="post">
			<input name="searchCustomerId" type="hidden"
				value="<%=searchCustomerId%>">
			<input name="searchCustomerName" type="hidden"
				value="<%=searchCustomerName%>">
			<input name="searchCompanyName" type="hidden"
				value="<%=searchCompanyName%>">
			<input name="searchCity" type="hidden" value="<%=searchCity%>">
			<input name="searchProvince" type="hidden"
				value="<%=searchProvince%>">
			<input name="searchState" type="hidden" value="<%=searchState%>">
			<input name="searchMobile" type="hidden" value="<%=searchMobile%>">
			<input name="searchSignature" type="hidden"
				value="<%=searchSignature%>">
			<input name="searchUserName" type="hidden"
				value="<%=searchUserName%>">
			<input name="searchUserSno" type="hidden" value="<%=searchUserSno%>">
			<input name="searchAmount" type="hidden" value="<%=searchAmount%>">
			<input name="searchType" type="hidden" value="<%=searchType%>">

			<table border="0" width="100%" height="25" cellspacing="0"
				cellpadding="0">
				<tr class="maintab">
					<table border="0" width="100%" height="25" cellspacing="0"
						cellpadding="0">
						<tr class="maintab">

							<jsp:include page="/kmjsp/app/customer_toolbar.jsp"></jsp:include>

							<td nowrap width="68%" align="right">
								<input id="<%=ViewPageHelper.PAGE_ACTION%>"
									name="<%=ViewPageHelper.PAGE_ACTION%>" type="hidden" value="" />
								共
								<%=customerPage.getTotalRows()%>条 /
								<%=customerPage.getPageCount()%>
								页
								<%
									if (customerPage.getPageIndex() > 1) {
								%>
								<img align="absmiddle" style="cursor: pointer;"
									onClick="goPage('FIRST_PAGE')"
									src="<%=basePath%>images/ico_first.gif" alt="首页" border="0" />
								<img align="absmiddle" style="cursor: pointer;"
									onClick="goPage('PREVIOUS_PAGE')"
									src="<%=basePath%>images/ico_prev.gif" alt="上一页" border="0" />
								<%
									} else {
								%>
								<img align="absmiddle" style="filter: Gray;"
									src="<%=basePath%>images/ico_first.gif" alt="首页" border="0" />
								<img align="absmiddle" style="filter: Gray;"
									src="<%=basePath%>images/ico_prev.gif" alt="上一页" border="0" />
								<%
									}
								%>
								第
								<font color="red"><%=customerPage.getPageIndex()%></font> 页
								<%
									if (customerPage.getPageIndex() < customerPage.getPageCount()) {
								%>
								<img align="absmiddle" style="cursor: pointer;"
									onClick="goPage('NEXT_PAGE')"
									src="<%=basePath%>images/ico_next.gif" alt="下一页" border="0" />
								<img align="absmiddle" style="cursor: pointer;"
									onClick="goPage('LAST_PAGE')"
									src="<%=basePath%>images/ico_last.gif" alt="尾页" border="0/">
								<%
									} else {
								%>
								<img align="absmiddle" style="filter: Gray;"
									src="<%=basePath%>images/ico_next.gif" alt="下一页" border="0" />
								<img align="absmiddle" style="filter: Gray;"
									src="<%=basePath%>images/ico_last.gif" alt="尾页" border="0" />
								<%
									}
								%>
							</td>
							<td nowrap width="1%">
								<img align="absmiddle" src="<%=basePath%>images/sbtn_split.gif" />
							</td>
							<td nowrap width="8%">
								转到&nbsp;
								<input id="<%=ViewPageHelper.PAGE_NO%>"
									name="<%=ViewPageHelper.PAGE_NO%>" type="text" size="2"
									value="<%=customerPage.getPageIndex()%>"
									onKeyPress="javascript:if(event.keyCode == 13){goPage('jump');}" />
								&nbsp;页
								<img align="absmiddle" style="cursor: pointer;"
									onClick="goPage('jump')" src="<%=basePath%>images/goto.gif"
									alt="执行" border="0" align="absmiddle">
							</td>
						</tr>
					</table>

					<div id="divList"
						style="vertical-align: top; width: 100%; overflow: auto;">
						<table border="0" style="border-collapse: collapse;"
							align="center" cellpadding="0" cellspacing="0" width="100%"
							class="maintab_content_table">
							<tr class="maintab_content_table_title">
								<th width="1%"></th>
								<th align="center" nowrap>
									客户码
								</th>
								<th align="center" nowrap>
									联系人
								</th>
								<th align="center" nowrap>
									身份证号码
								</th>
								<th align="center" nowrap>
									公司名称
								</th>
								<th align="center" nowrap>
									类型
								</th>
								<th align="center" nowrap>
									省份
								</th>
								<th align="center" nowrap>
									城市
								</th>
								<th align="center" nowrap>
									电话
								</th>
								<th align="center" nowrap>
									手机
								</th>
								<th align="center" nowrap>
									QQ
								</th>
								<th align="center" nowrap>
									E-mail
								</th>
								<th align="center" nowrap>
									出生日期
								</th>
								<th align="center" nowrap style="display: none">
									信息类别
								</th>
								<th align="center" nowrap>
									服务人员
								</th>
								<th align="center" nowrap>
									服务人角色
								</th>
								<th align="center" nowrap>
									创建时间
								</th>
								<th align="center" nowrap>
									修改时间
								</th>
								<th align="center" nowrap
									<%if (ACLTool.isModifyMemo(actionPermission)) {%> colspan="2"
									<%}%>>
									备注
								</th>
							</tr>
							<%
								if (list != null) {
									int size = list.size();
									for (int i = 0; i < size; i++) {
										Customer customer = (Customer) list.get(i);
							%>
							<tr onMouseOver="changeTrColor()" onMouseOut="changeTrColor()"
								title="<%=customer.getCustomerName()%>">
								<td nowrap align="center">
									<input class="rd" type="checkbox" name="itemselect"
										value="<%=customer.getCustomerId()%>" />
								</td>
								<td nowrap>
									<img border="0" src="<%=basePath%>images/jt_a.gif"
										onClick="showCustomerAttributes('<%=customer.getCustomerId()%>', '<%=customer.getCustomerName()%>')"
										style="cursor: hand" title="显示/隐藏">
									<%=customer.getCustomerId()%>
								</td>
								<td nowrap><%=customer.getCustomerName()%></td>
								<td nowrap><%=customer.getIdCard() != null ? customer
							.getIdCard() : ""%></td>
								<td nowrap><%=customer.getCompanyName()%></td>
								<td align="center" nowrap><%=customer.getType() != null ? customer.getType()
							: ""%></td>
								<td nowrap><%=customer.getProvince()%></td>
								<td nowrap><%=customer.getCity()%></td>
								<td nowrap><%=customer.getPhone()%></td>
								<td nowrap><%=customer.getMobile()%></td>
								<td nowrap><%=customer.getQQ()%></td>
								<td nowrap><%=customer.getEmail()%></td>
								<td nowrap><%=customer.getBirthday()%></td>
								<td nowrap align="center" style="display: none"><%=customer.getIsNew() == 0 ? "新信息" : "旧信息"%></td>
								<td nowrap><%=customer.getUserSno()%></td>
								<td nowrap><%=customer.getRoleId() != null ? customer
							.getRoleId() : "系统管理员"%></td>
								<td nowrap><%=customer.getCreateTime()%></td>
								<td nowrap><%=customer.getModifyTime()%></td>
								<td nowrap><%=customer.getMemo()%></td>
								<%
								if (ACLTool.isModifyMemo(actionPermission)) {
								%>
								<td nowrap>
									<img
										onClick="exportWindow('<%=basePath%>/kmjsp/app/memo.jsp?id=<%=customer.getId()%>&mode=CUSTOMER');"
										src="<%=basePath%>images/sbtn_mod.gif" alt="修改备注"
										align="absmiddle" style="cursor: pointer; margin-right: 0" />
								</td>
								<%
								}
								%>
							</tr>
							<tr id="tr_attribute_<%=customer.getCustomerId()%>"
								style="display: none">
								<td></td>
								<td colspan="16" id="td_attr_<%=customer.getCustomerId()%>">
									<div id="ds_attr_load_<%=customer.getCustomerId()%>"
										style="display: block; filter: Alpha(opacity =           80); background: #FFFFFF; width: 130px; height: 15px; position: absolute; padding: 5px 5px 5px 5px;">
										<font color="#FF0000"><img
												src="<%=basePath%>images/loading.gif" alt="数据加载中"
												class="icon1" align="absmiddle" />数据加载中...</font>
									</div>
									<div id="div_content_<%=customer.getCustomerId()%>"
										style="display: none; width: 100%;">
										<table id="table_<%=customer.getCustomerId()%>" width="60%"
											border="0" style="border-collapse: collapse;" align="left"
											cellpadding="0" cellspacing="0" class="maintab_content_table">
											<tbody id="table_<%=customer.getCustomerId()%>_tbody">
												<tr class="maintab_content_table_title_child">
													<th align="left" width="1%" nowrap>
														<input type="checkbox"
															onClick="selectAction('itemselect_<%=customer.getCustomerId()%>')"
															value="1" />

														<%
															if (ACLTool.isAdd(actionPermission)) {
														%>
														<a href="#" accesskey="n"
															onClick="dataHander('add','<%=basePath%>customerAttributes.crm?method=init&cid=<%=customer.getCustomerId()%>', viewForm.itemselect_<%=customer.getCustomerId()%>, '', 'itemselect_<%=customer.getCustomerId()%>');"><img
																align="absmiddle" src="<%=basePath%>images/sbtn_new.gif"
																alt="新增(Alt+N)" align="absmiddle"> </a>
														<%
															}
														%>
														<%
															if (ACLTool.isModify(actionPermission)) {
														%>
														<a href="#" accesskey="m"
															onClick="dataHander('modify','<%=basePath%>customerAttributes.crm?method=init&id=', viewForm.itemselect_<%=customer.getCustomerId()%>, '', 'itemselect_<%=customer.getCustomerId()%>');"><img
																align="absmiddle" src="<%=basePath%>images/sbtn_mod.gif"
																alt="修改(Alt+M)" align="absmiddle"> </a>
														<%
															}
														%>
														<%
															if (ACLTool.isDelete(actionPermission)) {
														%>
														<a href="#" accesskey="d"
															onClick="dataHander('delete','<%=basePath%>customerAttributes.crm?method=delete&id=', viewForm.itemselect_<%=customer.getCustomerId()%>, '', 'itemselect_<%=customer.getCustomerId()%>');"><img
																align="absmiddle" src="<%=basePath%>images/sbtn_del.gif"
																alt="删除(Alt+D)" align="absmiddle"> </a>
														<%
															}
														%>
														<%
															if (ACLTool.isSignatureYes(actionPermission)) {
														%>
														<a href="#" accesskey="q"
															onClick="dataHander('date','<%=basePath%>kmjsp/customer/selectDate.jsp?method=sign&v=1&t=<%=customer.getState()%>&id=', viewForm.itemselect_<%=customer.getCustomerId()%>, '', 'itemselect_<%=customer.getCustomerId()%>');"><img
																align="absmiddle"
																src="<%=basePath%>images/sbtn_selall.gif"
																alt="已签到(Alt+Q)" align="absmiddle"> </a>
														<%
															}
														%>
														<%
															if (ACLTool.isSignatureNo(actionPermission)) {
														%>
														<a href="#" accesskey="w"
															onClick="dataHander('signature','<%=basePath%>customerAttributes.crm?method=sign&v=0&id=', viewForm.itemselect_<%=customer.getCustomerId()%>, '', 'itemselect_<%=customer.getCustomerId()%>');"><img
																align="absmiddle"
																src="<%=basePath%>images/sbtn_rese.gif" alt="未签到(Alt+W)"
																align="absmiddle"> </a>
														<%
															}
														%>


													</th>
													<th align="center" nowrap>
														课程类别
													</th>
													<th align="center" nowrap>
														是否签到
													</th>
													<th align="center" nowrap>
														签到时间
													</th>
													<th align="center" nowrap>
														支付金额(元)
													</th>
													<th align="center" nowrap>
														支付时间
													</th>
												</tr>
											</tbody>
										</table>
									</div>
								</td>
							</tr>
							<%
								}
								}
							%>
						</table>
					</div>
					</form>
	</body>
</html>
<script>
document.getElementById("div_load").style.display = "none";</script>